package com.zhuzg.controller;

import com.zhuzg.domain.Order;
import com.zhuzg.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("order")
@Primary
public class OrderController {


    @Resource  // jdk  注解  根据名字从容器查找


    // spring 注解 根据类型从容器当中查找
    // 如果容器当中有重名的对象，则可能报错，解决办法 1）@Qualifier("")
    //  办法2）： 在实例化的时候加上 @Primary  ，这样重名的时候优先加载这个
    @Autowired
    OrderService orderService;

    @RequestMapping("create")
    public String createOrder(@RequestParam("userId") Integer userId,
                              @RequestParam("goodsId") Integer goodsId,
                              @RequestParam("buyNum")Integer buyNum){

        Order order = new Order(goodsId, buyNum, userId);
        orderService.createOrder(order);
      //  com.mysql.cj.jdbc.Driver d;

        return "ok";


    }

}
